package com.br.alex.view.asynctask;

import java.util.List;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;

import com.br.alex.view.CicloGuiaSingloton;
import com.br.alex.view.MainActivity;
import com.br.alex.view.model.Places;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

public class LoadPlaces extends AsyncTask<Void, Void, List<Places>> {
	
	//private FavoritosDB favorito;


	private List<ParseObject> todos;
	private Dialog progressDialog;
	private Context ctx;
	@Override
	protected void onPostExecute(List<Places> result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
		CicloGuiaSingloton sg = new CicloGuiaSingloton(ctx);
		sg.inserir(todos);
		Intent it = new Intent(ctx, MainActivity.class);
//		it.putExtra("rota", rota);
        ctx.startActivity(it);

		progressDialog.dismiss();
	}

	public LoadPlaces(Context ctx) {
		super();
		this.ctx = ctx;
		//favorito = new FavoritosDB(new ProjetoCesarDbHelper(ctx));
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
		progressDialog = ProgressDialog.show(ctx,"Carregando","Aguarde Carregando");

	}

	@Override
	protected void onProgressUpdate(Void... values) {
		// TODO Auto-generated method stub
		super.onProgressUpdate(values);
	}

	@Override
	protected List<Places> doInBackground(Void... params) {
		//ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("CicloAcao");
		ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Places");
		query.orderByDescending("created_at");
		query.setLimit(1000);

		try {
			todos = query.find();
		} catch (ParseException e) {

		}
		return null;
	}

//	@Override
//	protected Result doInBackground(List<ParseObject>... params) {
//		// TODO Auto-generated method stub
//		ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("CicloAcao");
//		query.orderByDescending("created_at");
//
//		try {
//			todos = query.find();
//		} catch (ParseException e) {
//
//		}
//		return null;
//
//	}

	

}
